package com.liuya.common.viewresolver;

import org.springframework.web.servlet.View;
import org.springframework.web.servlet.ViewResolver;
import org.springframework.web.servlet.view.InternalResourceViewResolver;
import org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver;

import java.util.Locale;

/**
 * @Author 刘亚
 * @Date 2016/12/19
 */
public class MyViewResolver implements ViewResolver {
    private InternalResourceViewResolver jspViewResolver = null;
    private FreeMarkerViewResolver htmlViewResolver = null;

    @Override
    public View resolveViewName(String viewName, Locale locale) throws Exception {
        if(!viewName.endsWith(".html")){
            return jspViewResolver.resolveViewName(viewName, locale);
        } else {
            return htmlViewResolver.resolveViewName(viewName, locale);
        }
    }

    public void setHtmlViewResolver(FreeMarkerViewResolver htmlViewResolver) {
        this.htmlViewResolver = htmlViewResolver;
    }

    public void setJspViewResolver(InternalResourceViewResolver jspViewResolver) {
        this.jspViewResolver = jspViewResolver;
    }
}
